﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dts = MedicalAdviser.Portable.DataTypes.DomainObjects;
using log = MedicalAdviser.Loggin;

namespace MedicalAdviser.DAL.WrappeTypes
{
    class ConvertSearchTypes
    {

        public static dts.CdoDrug ConvertQuickSearchTypes( spSelect_MedsSearchQuick_Result srcType  )
        {
            dts.CdoDrug drug;
            try
            {
                drug = new dts.CdoDrug();
                drug.CodEmbalagem =  Convert.ToInt32( srcType.EMB_ID);
                drug.CodMedicamento = Convert.ToInt32(srcType.CodMedicamento);
                drug.BusinessName = srcType.NomeMedicamento;
                drug.PharmaceuticalForm = srcType.FormaFarmaceutica;
                drug.Dci = srcType.DCI;
                drug.Pmu = srcType.PMU;
                drug.Dosage = srcType.Dosagem;
                drug.Pvp = srcType.PrecoUtente.HasValue ? srcType.PrecoUtente.Value : 0;
                drug.IsGeneric = srcType.Generico;
                drug.PackgeDescricao = srcType.EmbalagemDescricao;
                drug.TitularAim = srcType.TitularAIM;
                drug.NumberOfUsersRecomendations = srcType.Recomendations;
                

                return drug;
            }
            catch (Exception ex) 
            {
                log.Loggin.LOGGER.WriteEvent(
                    "MedicalAdviser.DAL.WrappeTypes.ConvertSearchTypes.ConvertQuickSearchTypes"
                    ,ex, log.LogginType.Error);
                
                throw ex;
            }
        }

        public static dts.CdoDrug ConvertDrugInformation(spSelect_MedicamentoInfo_Result tInput)
        {

            dts.CdoDrug drug;

            try
            {
                drug = new dts.CdoDrug();
                drug.CodEmbalagem = Convert.ToInt32(tInput.CodEmbalagem);
                drug.CodMedicamento = Convert.ToInt32(tInput.CodMedicamento);
                drug.BusinessName = tInput.NomeMedicamento;
                drug.PharmaceuticalForm = tInput.FormaFarmaceutica;
                drug.Dci = tInput.DCI;
                drug.Pmu = tInput.PMU.HasValue ? tInput.PMU.Value : 0 ;
                //drug.Posologia = tInput.
                drug.Dosage = tInput.Dosagem;
                drug.Pvp = tInput.PrecoUtente.HasValue ? Convert.ToDouble( tInput.PrecoUtente.Value ) : 0;
                drug.IsGeneric = tInput.Generico;
                drug.PackingDimension = tInput.DimensaoEmbalagem.HasValue ? tInput.DimensaoEmbalagem.Value.ToString() : "NA"  ;
                drug.Pmu = tInput.PMU.HasValue ? tInput.PMU.Value : 0;
                drug.PackgeDescricao = tInput.EmbalagemDescricao;
                drug.TitularAim = tInput.TitularAIM;
                drug.NumberOfUsersRecomendations = tInput.Recomendations;
                drug.RecommendByUser = tInput.UserAlreadyVote;

                return drug;
            }
            catch (Exception ex )
            {
                log.Loggin.LOGGER.WriteEvent(
                    "MedicalAdviser.DAL.WrappeTypes.ConvertSearchTypes.ConvertDrugInformation"
                    , ex, log.LogginType.Error);
                
                throw ex;
            }

        }

        public static dts.CdoDrug GetEquivalentsLowCost(spSelect_MedicamentosEquivalentes_Result tInput)
        {

            dts.CdoDrug drug;

            try
            {
                drug = new dts.CdoDrug();
                drug.CodEmbalagem = Convert.ToInt32(tInput.EMB_ID);
                drug.CodMedicamento = Convert.ToInt32(tInput.MED_ID);
                drug.BusinessName = tInput.NOME;
                drug.PharmaceuticalForm = tInput.FormaFarmaceutica;
                drug.Dci = tInput.DCI;
                drug.Dosage = tInput.DOSAGEM;
                drug.Pvp = tInput.PrecoUtente.HasValue ? Convert.ToDouble( tInput.PrecoUtente.Value ) : 0;
                drug.IsGeneric = tInput.Generico;
                drug.PackingDimension = tInput.DimensaoEmbalagem.HasValue ? tInput.DimensaoEmbalagem.Value.ToString() : "NA"  ;
                drug.Pmu = tInput.PMU.HasValue ? tInput.PMU.Value : 0;
                drug.PackgeDescricao = tInput.DESCR;
                drug.TitularAim = tInput.TitularAIM;

                return drug;
            }
            catch (Exception ex )
            {
                log.Loggin.LOGGER.WriteEvent(
                    "MedicalAdviser.DAL.WrappeTypes.ConvertSearchTypes.GetEquivalentsLowCost"
                    , ex, log.LogginType.Error);
                
                throw ex;
            }

        }

    }
}
